#include<iostream>
using namespace std;
/**
 * 类中有指针属性，必须自定义析构函数删除指针，自定义拷贝构造函数-->深拷贝，防止浅拷贝带来的指针悬浮
 */
class Person
{
private:
  /* data */
public:
  Person(int age, int height) {
    age = age;
    m_height = new int(height);
  }
  Person(const Person &p) {
    age = p.age;
    m_height = new int(*p.m_height);
  }
  ~Person() {
    if (m_height != NULL) {
      delete m_height;
      m_height = NULL;
    }
  }
  int* m_height;
  int age;
};


int main() {

  // Person p1 = {31, 173};  // Person定义了有参构造无默认构造函数， 这样写报错
  Person p1(31, 173);

  Person p2 = Person(p1);
  
  return 0;
}